package l1j.server.server.model.damage;

import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.templates.L1MagicDoll;
import l1j.server.server.utils.Random;

public class L1DamageOnPc {
	private L1PcInstance _target;
	private L1Dmg _dmg;

	public L1DamageOnPc(L1Dmg dmg, L1PcInstance target) {
		_target = target;
		_dmg = dmg;
	}

	// npc-->pc時防禦影響有減傷
	public void calcDamageReductionByAc() {
		int ac = Math.max(0, 10 - _target.getAc());
		int acDefMax = _target.getClassFeature().getAcDefenseMax(ac);
		_dmg.sub(Random.nextInt(acDefMax + 1));
	}

	public void calcDamageOnPc() {
		_dmg.sub(_target.getDamageReductionByArmor()) // 防具によるダメージ軽減
				// 魔法娃娃效果 - 傷害減免
				.sub(L1MagicDoll.getDamageReductionByDoll(_target));

		// 輔助裝備（符石） 減傷
		double mul = 1.0;
		for (L1ItemInstance armors : _target.getEquipSlot().getArmors()) {
			mul -= armors.getRuneDrPercent() / 100.0;
		}
		_dmg.mul(mul);
	}
}
